<template>
  <div>
    <div>
      <el-carousel>
        <el-carousel-item>
          <img class="carousel-img" src="../assets/150707.jpg" />
        </el-carousel-item>
        <el-carousel-item>
          <img class="carousel-img" src="../assets/150724.jpg" />
        </el-carousel-item>
        <el-carousel-item>
          <img class="carousel-img" src="../assets/150737.jpg" />
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="content-wrap">
      <div class="content-left">
        <div class="content-header">
          <div>公告信息</div>
          <!-- <div class="more">更多 &gt; &gt;</div> -->
        </div>
        <div class="content-list">
          <div
            class="content-item"
            v-for="item of announceList"
            :key="item.id"
            @click="$refs.info.openDia(item, 1)"
          >
            {{ item.title }}
          </div>
        </div>
      </div>
      <div class="content-center">
        <div class="library-wrap">
          <div class="library-item" v-for="item of libraryList" :key="item.id">
            <img class="library-img" :src="`//127.0.0.1:9003/${item.image}`" />
            <div class="library-name">
              {{ item.name }}
              <span>
                <el-button size="mini" type="primary" @click="showRule(item)">预约规则</el-button>
              </span>
            </div>
            <div class="library-number">
              座位数：<span style="font-weight: 600">{{ item.number }}</span>
            </div>
            <div class="library-details">
              {{ item.details }}
            </div>
            <div class="library-btn">
              <el-button @click="$router.push(`/seat/${item.id}`)" size="small" type="warning">
                预约座位
              </el-button>
              <el-button
                size="small"
                style="margin-left: 15px"
                type="danger"
                @click="$router.push(`/seminar/${item.id}`)"
                >预约研讨室</el-button
              >
            </div>
          </div>
        </div>
      </div>
      <div class="content-right">
        <div class="content-header">
          <div>活动通知</div>
          <!-- <div class="more">更多 &gt; &gt;</div> -->
        </div>
        <div class="content-list">
          <div
            class="content-item"
            v-for="item of activeList"
            :key="item.id"
            @click="$refs.info.openDia(item, 2)"
          >
            {{ item.topic }}
          </div>
        </div>
      </div>
    </div>

    <info ref="info"></info>

    <el-dialog title="预约规则" :visible.sync="visible" width="30%">
      <div>
        {{ rule }}
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="visible = false">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import request from '@/req'
import info from './info.vue'
export default {
  components: { info },
  data() {
    return {
      announceList: [],
      activeList: [],
      libraryList: [],
      visible: false,
      rule: '',
    }
  },
  created() {
    this.getAnnouncementTop()
    this.getActiveTop()
    this.getLibraryList()
  },
  methods: {
    async getAnnouncementTop() {
      const res = await request.get('/announcement/getAnnouncementTop')
      this.announceList = res ? res : []
    },
    async getActiveTop() {
      const res = await request.get('/activity/getActivityTop')
      this.activeList = res ? res : []
    },
    async getLibraryList() {
      const res = await request.get('/library/getLibraryList')
      this.libraryList = res ? res : []
    },
    showRule(data) {
      this.rule = data.inform
      this.visible = true
    },
  },
}
</script>

<style scoped>
.carousel-img {
  height: 300px;
  width: 100%;
  object-fit: cover;
}

.content-wrap {
  display: flex;
  flex-direction: row;
  height: calc(100vh - 350px);
  width: 100%;
  padding: 10px;
}

.content-wrap .content-center {
  flex: 1;
  height: 100%;
  padding: 0 15px;
}

.content-wrap .content-right,
.content-wrap .content-left {
  width: 25vw;
  height: 100%;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 10px;
}

.content-header {
  font-size: 24px;
  font-weight: 500;
  border-bottom: 2px solid #eee;
  padding-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.content-header .more {
  font-size: 20px;
  color: #888;
  cursor: pointer;
}

.content-header .more:hover {
  color: #000;
}
.content-list {
  padding-top: 10px;
}
.content-item {
  font-size: 18px;
  padding: 10px;
  border-bottom: 1px solid #ccc;
  padding-left: 25px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content-item:hover {
  color: #4f4fbe;
}

.library-wrap {
  display: flex;
  flex-direction: row;
  height: 100%;
  /* border-top-left-radius: 8px;
  border-top-right-radius: 8px; */
}
.library-wrap .library-item {
  display: flex;
  flex-direction: column;
  flex: 1;
  margin: 0 8px;
  border-left: 1px solid #ccc;
  border-right: 1px solid #ccc;
  border-bottom: 1px solid #ccc;
  height: 100%;
  border-radius: 8px;
  padding-bottom: 5px;
}

.library-item .library-img {
  width: 100%;
  height: 40%;
  object-fit: fill;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}
.library-name {
  font-size: 18px;
  font-weight: 600;
  padding: 8px;
  display: flex;
  justify-content: space-between;
}
.library-details {
  padding: 8px;
  flex: 1;
}

.library-number {
  padding: 8px;
}

.library-btn {
  padding: 0 20px;
  align-self: center;
}
</style>
